
--
module("UI.Windows.NewGameNoticeWin",package.seeall)

local UIUtility = require("UI.Utility")
local UIWindow = require("UI.UIWindow").UIWindow

NewGameNoticeWin = UIWindow:new()

NewGameNoticeWin.name = "NewGameNoticeWin" 


function NewGameNoticeWin:Init()
    local t = self.Container.transform
    self.OkButton = UIUtility.GetChildTransform("OkBtn",t,true)
    self.NoButton = UIUtility.GetChildTransform("NoBtn",t,true)
    local labelt = UIUtility.GetChildTransform("MsgLabel",t,true)
    self.MsgLabel = labelt:GetComponent('UILabel')
    self.Grid = UIUtility.FindContorl('UIGrid',"Grid",t)
    self.CloseBtn = UIUtility.GetChildTransform("Close",t,true) 
    self.closeDi = UIUtility.GetChildTransform("closeDi",t,true) 
    UIHelper.BindUIEvnet("Click",self.OnOkClick,self.OkButton.gameObject)--绑定按钮事件
    UIHelper.BindUIEvnet("Click",self.OnNoClick,self.NoButton.gameObject)--绑定按钮事件
    UIHelper.BindUIEvnet("Click",self.CloseBtnClick,self.CloseBtn.gameObject)
    UIHelper.BindUIEvnet("Click",self.CloseBtnClick,self.closeDi.gameObject)
end

function NewGameNoticeWin:CloseBtnClick()
    NewGameNoticeWin:Close(2)
end

function NewGameNoticeWin:SetMsg(msg,ok,no)
    self.OkButton.gameObject:SetActive(true)
    self.NoButton.gameObject:SetActive(true)
    self.onOk = ok
    self.onNo = no
    self.MsgLabel.text = msg
    if ok == nil and no == nil then
        --Debug.log("++LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLOOOO")
        self.NoButton.gameObject:SetActive(false)
    end
    --[[if ok and no==nil then
        self.NoButton.gameObject:SetActive(false)
    end]]
    self.Grid:Reposition()
end

function  NewGameNoticeWin.OnOkClick()
    NewGameNoticeWin:Close(2)
 	if nil ~= NewGameNoticeWin.onOk then
        if type(NewGameNoticeWin.onOk) == "function"  then
            NewGameNoticeWin.onOk()
        end
    end
    NewGameNoticeWin:Reset()
end

function  NewGameNoticeWin.OnNoClick()
    NewGameNoticeWin:Close(2)
 	if nil ~= NewGameNoticeWin.onNo then
        if type(NewGameNoticeWin.onNo) == "function"  then
            NewGameNoticeWin.onNo()
        end
    end
    NewGameNoticeWin:Reset()
end

function NewGameNoticeWin:Reset()
    self.onOk = nil
    self.onNo = nil
    self.MsgLabel.text = ""
    -- self.OkButton.gameObject:SetActive(true)
    -- self.NoButton.gameObject:SetActive(true)
end

function NewGameNoticeWin:CreateWin()
	--加载资源，创建Unity对象
	Debug.log("开始创建界面 " .. self.name)
	
	local GameObject = UnityEngine.GameObject
	local ResMgr = require("Res.ResMgr").ResMgr
	local BehaviourEvent = require("BehaviourEvent").BehaviourEvent
	
	local root = GameObject(self.name)
	root.transform.parent = GameObject.Find("TopUIRoot").transform
	root.transform.localScale = Vector3(1, 1, 1);
	root.transform.localPosition = Vector3(0, 0, 0);	
	
	local obj = ResMgr:LordBySyn("UI/" .. self.name, root)
	local Ing = GameObject.Instantiate(obj)
	Ing.transform.parent = root.transform
	Ing.transform.localScale = Vector3(1, 1, 1);
	Ing.transform.localPosition = Vector3(0, 0, 0);
	self.Container = Ing:GetComponent('UIPanel')
	
	self.Root = root
	
	function OnDestroy()
		self.Container = nil
		self.Root = nil
		Debug.log("销毁界面" .. self.name)
		if not self.OnDestroy or type(self.OnDestroy) ~= "function" then
			return
		end
		self:OnDestroy()
	end
	
	BehaviourEvent:Bind("OnDestroy", root, OnDestroy) --绑定销毁事件
	
	Debug.log("界面创建完毕 " .. self.name)
end 